//package com.github.pig.admin.common.listener;
//
//import com.baomidou.mybatisplus.mapper.EntityWrapper;
//import com.github.pig.admin.service.zuul.SysZuulRouteService;
//import com.github.pig.common.constant.CommonConstant;
//import com.github.pig.common.entity.SysZuulRoute;
//import com.xiaoleilu.hutool.collection.CollUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.ApplicationArguments;
//import org.springframework.boot.ApplicationRunner;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
///**
// * @author lengleng
// * @date 2018/5/16
// */
//@Slf4j
//@Component
//public class RouteConfigInitListener implements ApplicationRunner {
//    @Autowired
//    private RedisTemplate redisTemplate;
//    @Autowired
//    private SysZuulRouteService sysZuulRouteService;
//
//    /**
//     * Callback used to run the bean.
//     * 初始化路由配置的数据，避免gateway 依赖业务模块
//     *
//     * @param args incoming application arguments
//     */
//    @Override
//    public void run(ApplicationArguments args) {
//        log.info("开始初始化路由配置数据");
//        EntityWrapper wrapper = new EntityWrapper();
//        wrapper.eq(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
//        List<SysZuulRoute> routeList = sysZuulRouteService.selectList(wrapper);
//        if (CollUtil.isNotEmpty(routeList)) {
//            redisTemplate.opsForValue().set(CommonConstant.ROUTE_KEY, routeList);
//            log.info("更新Redis中路由配置数据：{}条", routeList.size());
//        }
//        log.info("初始化路由配置数据完毕");
//    }
//}